<template>
  <a-date-picker :value="modelValueShow" :show-time="showTime" :format="format" :placeholder="placeholder" @change="changeValue" />
</template>

<script lang="ts">
import { defineComponent } from 'vue'

import moment from 'moment'

export default defineComponent({
  name: 'DateUnixTime',
  props: {
    modelValue: Number,
    showTime: {
      type: [Object, Boolean],
      default() {
        return { defaultValue: moment('00:00:00', 'HH:mm:ss') }
      }
    },
    format: {
      type: String,
      default: 'YYYY-MM-DD HH:mm:ss',
    },
    placeholder: {
      type: String,
      default: '选择日期时间',
    },
  },
  emits: [
    'update:modelValue',
    'change'
  ],
  data() {
    return {
    }
  },
  computed: {
    modelValueShow() {
      return this.modelValue ? moment(this.modelValue) : this.modelValue
    },
  },
  methods: {
    changeValue(date, dateString) {
      this.$emit('update:modelValue', date ? +date : null)
      this.$emit('change', date ? +date : null)
    },
  },
  mounted() {
  }
})
</script>

<style scoped lang="less">

</style>
